function log(val) {
    console.log(val);
}

var vm = new Vue({
    el: "#app",

    data: {
        items: [],
        itemsLen: '',
        totalPageNum: 0,
        pageSize: 0,
        currentPageNum: 0,


    },

    filters: {},

    computed: {},

    mounted: function () {
        // this.showList();
        this.getPager();
    },

    methods: {
        showList: function () {
            this.$http.get("/Menu/getList").then(function (data) {
                this.items = data.data.data;
            })
        },
        member_del: function (e, id) {
            if (confirm("你确定删除吗？")) {
                this.$http.get("/Menu/deleteMenu", {'id': id}).then(function (data) {
                    var val = this.items.indexOf(e);
                    this.items.splice(val, 1)
                    layer.msg('已删除!', {icon: 1, time: 1000});
                })
            }
        },
        member_edit: function (title, url, id, w, h) {
            layer_show(title, url + "/" + id, w, h);
        },
        updateBySort: function () {
            var menuList = this.items;
            var ids = new Array();
            var sorts = new Array();
            for (var i = 0; i < menuList.length; i++) {
                ids.push(menuList[i].id);
                sorts.push(menuList[i].sort);
            }
            $.post("/Menu/updateBySort", {ids: ids, sorts: sorts}, function (data) {
                if (data.msg == "success") {
                    location.reload();
                }
            });
        },
        getPager: function (n) {
            this.$http.get("/Menu/page", {pageNum: n, pageSize: this.pageSize}).then(function (data) {
                this.totalPageNum = data.data.totalPageNum;
                this.pageSize = data.data.perPageSize;
                this.currentPageNum = data.data.currentPageNum;
                this.items = data.data.entitys;
            });
        },
        back: function () {
            if (this.currentPageNum != 1) {
                this.$http.get("/Menu/page", {
                    pageNum: this.currentPageNum - 1,
                    pageSize: this.pageSize
                }).then(function (data) {
                    this.totalPageNum = data.data.totalPageNum;
                    this.pageSize = data.data.perPageSize;
                    this.currentPageNum = data.data.currentPageNum;
                    this.items = data.data.entitys;
                });
            }
        },
        go: function () {
            if (this.currentPageNum < this.totalPageNum) {
                this.$http.get("/Menu/page", {
                    pageNum: this.currentPageNum + 1,
                    pageSize: this.pageSize
                }).then(function (data) {
                    this.totalPageNum = data.data.totalPageNum;
                    this.pageSize = data.data.perPageSize;
                    this.currentPageNum = data.data.currentPageNum;
                    this.items = data.data.entitys;
                });
            }
        },
        member_edit: function (title, url, id, w, h) {
            layer_show(title, url + "?id="+ id, w, h);
        },
    }
});